package org.ecinc.mvc.form;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class FillForm {

	public FillForm(){}
	
	@SuppressWarnings("rawtypes")
	public static ActionForm fill(String className, HttpServletRequest request){
		ActionForm form = null;
		
		try {
			Class clazz = Class.forName(className);
			form = (ActionForm) clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field f : fields) {
				f.setAccessible(true);//拆箱
				f.set(form, request.getParameter(f.getName()));
				f.setAccessible(false);//装箱
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return form;
	}
}
